import { _decorator, Component, Node, Label, director } from 'cc';
import { SSS_Consts } from "../../../Script/Data/SSS_Consts";
import { ShuZiHuaRongDao_GameData } from "./ShuZiHuaRongDao_GameData";
import { ShuZiHuaRongDao_GameStorage } from "./ShuZiHuaRongDao_GameStorage";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';

const { ccclass, property } = _decorator;

@ccclass('ShuZiHuaRongDaoMainScene')
export default class ShuZiHuaRongDao_Main_Scene extends Component {
    public static Instance: ShuZiHuaRongDao_Main_Scene;
    @property(Node)
    public Button_back: Node | null = null;
    @property(Node)
    public Button_3x3: Node | null = null;
    @property(Node)
    public Button_4x4: Node | null = null;
    @property(Node)
    public Button_5x5: Node | null = null;
    @property(Node)
    public Button_6x6: Node | null = null;
    @property(Node)
    public Button_7x7: Node | null = null;
    @property(Node)
    public Button_8x8: Node | null = null;
    @property(Node)
    public Button_9x9: Node | null = null;
    @property(Node)
    public Button_10x10: Node | null = null;
    @property(Label)
    public Label_best_time_3x3: Label | null = null;
    @property(Label)
    public Label_best_time_4x4: Label | null = null;
    @property(Label)
    public Label_best_time_5x5: Label | null = null;
    @property(Label)
    public Label_best_time_6x6: Label | null = null;
    @property(Label)
    public Label_best_time_7x7: Label | null = null;
    @property(Label)
    public Label_best_time_8x8: Label | null = null;
    @property(Label)
    public Label_best_time_9x9: Label | null = null;
    @property(Label)
    public Label_best_time_10x10: Label | null = null;
    onLoad() {
        ShuZiHuaRongDao_Main_Scene.Instance = this;

        ShuZiHuaRongDao_GameStorage.initData();
        this.ShowOn();
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }
    ShowOff() {
        this.node.destroy();
        this.RemoveListener();
    }
    Refresh() {
        this.Label_best_time_3x3.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_3x3`].best_time);
        this.Label_best_time_4x4.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_4x4`].best_time);
        this.Label_best_time_5x5.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_5x5`].best_time);
        this.Label_best_time_6x6.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_6x6`].best_time);
        this.Label_best_time_7x7.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_7x7`].best_time);
        this.Label_best_time_8x8.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_8x8`].best_time);
        this.Label_best_time_9x9.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_9x9`].best_time);
        this.Label_best_time_10x10.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[`game_mode_10x10`].best_time);
    }
    AddListener() {
        this.Button_back.on(Node.EventType.TOUCH_END, this.On_Button_back, this);

        this.Button_3x3.on(Node.EventType.TOUCH_END, this.On_Button_3x3, this);
        this.Button_4x4.on(Node.EventType.TOUCH_END, this.On_Button_4x4, this);
        this.Button_5x5.on(Node.EventType.TOUCH_END, this.On_Button_5x5, this);
        this.Button_6x6.on(Node.EventType.TOUCH_END, this.On_Button_6x6, this);
        this.Button_7x7.on(Node.EventType.TOUCH_END, this.On_Button_7x7, this);
        this.Button_8x8.on(Node.EventType.TOUCH_END, this.On_Button_8x8, this);
        this.Button_9x9.on(Node.EventType.TOUCH_END, this.On_Button_9x9, this);
        this.Button_10x10.on(Node.EventType.TOUCH_END, this.On_Button_10x10, this);
    }
    RemoveListener() {
        this.Button_back.off(Node.EventType.TOUCH_END, this.On_Button_back, this);

        this.Button_3x3.off(Node.EventType.TOUCH_END, this.On_Button_3x3, this);
        this.Button_4x4.off(Node.EventType.TOUCH_END, this.On_Button_4x4, this);
        this.Button_5x5.off(Node.EventType.TOUCH_END, this.On_Button_5x5, this);
        this.Button_6x6.off(Node.EventType.TOUCH_END, this.On_Button_6x6, this);
        this.Button_7x7.off(Node.EventType.TOUCH_END, this.On_Button_7x7, this);
        this.Button_8x8.off(Node.EventType.TOUCH_END, this.On_Button_8x8, this);
        this.Button_9x9.off(Node.EventType.TOUCH_END, this.On_Button_9x9, this);
        this.Button_10x10.off(Node.EventType.TOUCH_END, this.On_Button_10x10, this);
    }
    On_Button_back() {
        console.log("On_Button_back---");
        this.ShowOff();
        director.loadScene(SSS_Consts.SceneName.MainScene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_3x3() {
        console.log("On_Button_3x3---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_3x3`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_4x4() {
        console.log("On_Button_4x4---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_4x4`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_5x5() {
        console.log("On_Button_5x5---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_5x5`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_6x6() {
        console.log("On_Button_6x6---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_6x6`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_7x7() {
        console.log("On_Button_7x7---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_7x7`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_8x8() {
        console.log("On_Button_8x8---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_8x8`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_9x9() {
        console.log("On_Button_9x9---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_9x9`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_10x10() {
        console.log("On_Button_10x10---");

        ShuZiHuaRongDao_GameData.Game_mode = `game_mode_10x10`;
        director.loadScene(SSS_Consts.SceneName.ShuZiHuaRongDao_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
}